<%@page import="com.tpc.server.systeme.service.AuthentificationServiceImpl"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="com.tpc.dao.extend.UserAppEngine"%>

<%
String strUsername = null;
String strPassword = null;
if (request.getParameter("tpcusername") != null) {
    if (request.getParameter("tpcusername").length() > 1) {
        strUsername = request.getParameter("tpcusername");
    }
}
if (request.getParameter("tpcpassword") != null) {
    if (request.getParameter("tpcpassword").length() > 1) {
        strPassword = request.getParameter("tpcpassword");
    }
}
AuthentificationServiceImpl authenticate = new AuthentificationServiceImpl();
UserAppEngine user = authenticate.simpleLogin(strUsername,strPassword,request);
String loginPath = "denied";
/** set cookies **/

if (user != null) {
    String firstname = user.getFirstName();
    firstname = URLEncoder.encode(firstname,"UTF-8");    
    String lastname = user.getLastName();
    lastname = URLEncoder.encode(lastname,"UTF-8");  
	Cookie cookie1 = new Cookie("krypton_userid",new Integer(user.getId()).toString());
	Cookie cookie2 = new Cookie("krypton_username",user.getUsername());
	Cookie cookie3 = new Cookie("krypton_firstname",firstname);
	Cookie cookie4 = new Cookie("krypton_lastname",lastname);
	Cookie cookie5 = new Cookie("krypton_dictionary",user.getLangue().getCode());
	Cookie cookie6 = new Cookie("krypton_group",new Integer(user.getGroupeDefaut()).toString());
	response.addCookie(cookie1);
	response.addCookie(cookie2);
	response.addCookie(cookie3);
	response.addCookie(cookie4);
	response.addCookie(cookie5);
	response.addCookie(cookie6);
	loginPath = user.getLoginPath();
}
response.getWriter().write(loginPath);
%>